// ====================================

// header_full 通用头处理

// ====================================

var cookieUrl;cookieUrl=$.cookie('cookieUrl');$.cookie('cookieUrl',window.location,{expires:2,path:'/'});if(document.referrer!=""){cookieUrl=document.referrer}$.cookie('preCookieUrl',cookieUrl,{expires:2,path:'/'});


//原先common/common2.js 中方法


function checkNum(str){return str.match(/\D/)==null}function getValueOfSelect(id){var objs=document.getElementById(id);if(objs==null){return}if(objs.selectedIndex>=0){return objs.options[objs.selectedIndex].value}return""}function setValueOfSelect(id,value){var objs=document.getElementById(id);for(var i=0;i<objs.options.length;i++){if(objs.options[i].value==value){objs.options[i].selected="selected"}}}function getRadioCheckedValue(radioName){var value="";var objs=document.getElementsByName(radioName);for(var i=0;i<objs.length;i++){if(objs[i].checked){value=objs[i].value}}return value}function radioDoNotChecked(radioName){var value="";var objs=document.getElementsByName(radioName);for(var i=0;i<objs.length;i++){objs[i].checked=false}}function divContentRoll(topDiv,contentDiv,tempDiv){var speed=60;var demo=document.getElementById(topDiv);var demo1=document.getElementById(contentDiv);var demo2=document.getElementById(tempDiv);demo2.innerHTML=demo1.innerHTML;function Marquee(){if((demo2.offsetTop-demo.scrollTop)<=0){demo.scrollTop=0}else{demo.scrollTop++}}var MyMar=setInterval(Marquee,speed);demo.onmouseover=function(){clearInterval(MyMar)};demo.onmouseout=function(){MyMar=setInterval(Marquee,speed)}}function countCharacters(str,size){var totalCount=0;var newStr="";for(var i=0;i<str.length;i++){var c=str.charCodeAt(i);if((c>=1&&c<=126)||(65376<=c&&c<=65439)){totalCount++}else{totalCount+=2}if(totalCount<size){newStr=str.substring(0,i+1)}else{return newStr+"..."}}return newStr}function validateLength(str,size){return(str.getByteLength()<=size)?true:false}function autoNewLine(str,size){beginPos=0;var totalCount=0;var newStr="";for(var i=0;i<str.length;i++){var c=str.charCodeAt(i);if((c>=1&&c<=126)||(65376<=c&&c<=65439)){totalCount++}else{totalCount+=2}if(totalCount>=size){newStr+=str.substring(beginPos,i+1)+"<br/>";totalCount=0;beginPos=i+1}}if(beginPos!=str.length){newStr+=str.substr(beginPos)}return newStr}function isMobile(_str){return YM.valid.isMobile(_str)}function verifyAddress(email){return YM.valid.isEmail(email)}function validateEmail(email){return YM.valid.isEmail(email)}function validateMobile(mobile){return YM.valid.isMobile(_str)}function lenReg(str){return str.getByteLength()}function formatDoubleValue(value,symbols){return parseFloat(value).toFixed(symbols)}





// old function





function setTab(name,cursel,n) { for(var i=1;i<=n;i++){var tab=document.getElementById(name+i);var con=document.getElementById("con_"+name+"_"+i);tab.className=i==cursel?"hover":"";con.style.display=i==cursel?"block":"none"} }





function showLoginDiv(callback) { YM.login.pop(function(member){if($.isFunction(callback)){callback(member)}else if(typeof(callback)=='string'){eval(callback)}}) }





function needLogin(toUrl) { YM.login.pop(toUrl); }





function isLogin() { var html=$.ajax({url:YM.login.servicePath+'portal/loginState.jspa',cache:false,async:false}).responseText;if(html=="0"){return false;}else if(html=="1"){return true;} } 





//---------------------------------





// header处理





(function($) {





	// ----------------------------





	YM.namespace('YM.page.header');





	// ----------------------------





	// 跨域处理





	YM.page.header.isSubDomain = function() {





		var darr = document.domain.split('.');





		return (darr.length==3 && darr[0]!='www' && isNaN(darr[0]));





	}();





	if (YM.page.header.isSubDomain) {





		YM.login.setServicePath('http://www.yesmywine.com/');





	}





	//-----------------------------





	YM.page.header.serviceAPI = {





		'accountLink':  YM.login.servicePath +'personalCenter/showIndex.jspa?page=1',





		'logoutLink':   YM.login.servicePath +'user/userExit.jspa',





		'messageLink':  YM.login.servicePath +'memberMessage/index.jspa',





		'keySuggest': 	YM.login.servicePath +'search/suggest.jspa?q={q}&callback=?'





	};





	//-----------------------------





	YM.page.header.init = function() {





		this.container = $('#header');





		this.initHeadBar();





		this.initHeadSearch();





		this.initHeadShopCart();





		this.initHeadCategory();





		this.initHeadNavLinks();





		this.loadHeadData();





		this.initFooter();





	};





	//-----------------------------





	YM.page.header.initHeadBar = function() {





		var headbarElm = this.container.find('.head-bar');





		if (headbarElm.size()==0) return;





		headbarElm.find('.dropdown').bindYMUI('ElementHover', { hoverClass:'dropdown-hover' });





		if (this.container.find('.head-logo .logo-channel').size()>0) {





			headbarElm.find('.myaccount').addClass('bldr').before('<li class="bold"><a href="http://www.yesmywine.com/" target="_blank">也买酒首页</a></li>');





		}





		headbarElm.find('a.txt-login, a.txt-register').each(function() {





			this.href = this.href +'?to='+ encodeURIComponent(location.href);





		});





	};





	// 搜索框初始化





	YM.page.header.initHeadSearch = function() {





		var headsrhElm = this.container.find('.head-search');





		if (headsrhElm.size()==0) return;





		//





		if ($('#headSuggestArea').size()==0) {





			$('body').append('<ul id="headSuggestArea" class="searchsuggest"></ul>');





		}





		//





		var searchElm = this.container.find('.head-search .txt-keyword');





		searchElm.bind('submitKeyword', function() {





			$(this).next().click();





		});





		searchElm.bind('keypress', function(e) {





			try {





                var code = e.which || e.keyCode || 0;





				if (code == 13) $(this).trigger('submitKeyword');





			} catch(err) {}





		});





		searchElm.bindYMUI('InputHint', { hint:'输入您要查找的商品名称', hintColor:'#cccccc', hintKeep:false, required:true });





		searchElm.bindYMUIExtend('suggest', 'suggest', { 





			url: this.serviceAPI.keySuggest,





			listElm:  $('#headSuggestArea'),





			itemTmpl: '<li key="{key}"><i>{num}件商品</i><span class="mr70">{txt}</span></li>',





			itemExec: function(key, data) {





				return { 'key':data[0], 'txt':data[0].replace(key,'<em>'+key+'</em>'), 'num':data[1] };





			}





		});





	};





	// 购物车初始化





	YM.page.header.initHeadShopCart = function() {





		var headcartElm = $('.head-shopcart');





		if (headcartElm.size()==0) return;





		headcartElm.hover(function() {





			$(this).addClass('head-shopcart-hover');





			YM.page.header.cart.slideStop();





		}, function() {





			$(this).removeClass('head-shopcart-hover');





		});





		var pathname = document.location.pathname, hostname = document.location.hostname;





        //全站浮动购物车





		//if (hostname=='list.yesmywine.com' || pathname.startWith('/goods') || pathname.startWith('/list') || pathname.startWith('/marketing/sales') || pathname.startWith('/marketing/seckill') ||$('.e-addtopopcart').size()>0) {





			YM.page.header.cart.float();





		//}





	};





	YM.page.header.initHeadCategory = function() {





		var headcateElm = this.container.find('.head-nav .categorys');





		if (headcateElm.size()==0) return;





		//针对IE6下不支持:hover伪类的处理





		if ($.browser.isIE6) {





			if ($('body').hasClass('s950') || $('body').hasClass('s960')) {





				headcateElm.bindYMUI('ElementHover', {hoverClass:'categorys-hover'});





			}





			headcateElm.find('dl').bindYMUI('ElementHover', {hoverClass:'hover'});





			headcateElm.find('.subcates, .relcates').each(function() {





				$(this).find('li:first').addClass('first');





			});





		}





	};





	YM.page.header.initHeadNavLinks = function() {





		var headlinkElm = this.container.find('.head-nav .navlinks');





		if (headlinkElm.size()==0) return;





		var pathname = window._ymw_pathname || document.location.pathname;





		if (pathname=='/' || pathname=='') pathname = '/index.html';





		headlinkElm.find('li').each(function() {





			if ($(this).attr('folder')) {





				if (pathname.startWith($(this).attr('folder'), true)) {





					$(this).addClass('on').siblings('.on').removeClass('on');





				}





			}





		});





	};





	//-----------------------------





	YM.page.header.loadHeadData = function() {





		var headbarElm = this.container.find('.head-bar');





		if (headbarElm.size()==0) return;





		YM.login.getUserInfo(function(userData, headData) {





			if (userData.isLogin) {





				YM.page.header.showUserInfo(userData, headData.loginInfo);





			} else {





				headbarElm.find('em.member-count').html(headData.miscInfo.memberCount).parent().show();





			}





			YM.page.header.cart.show(headData.cartInfo);





		});





	};





	// 加载用户信息





	YM.page.header.showUserInfo = function(d, d2) {





		var headbarElm = this.container.find('.head-bar');





		var userElm = headbarElm.find('.userinfos');





		// 显示用户信息





		var tmpl = [





			'<li style="height:16px;overflow:hidden;">您好，<a href="{accountLink}">{nickName} <img align="absmiddle" width="16" height="16" src="images/{memberTinyIcon}.png" /></a></li>',





			'<li class="bldr message"><a href="{messageLink}" target="_blank">新消息<em></em></a></li>',





			'<li class="bldr"><a href="{logoutLink}" class="txt-logout" onclick="YM.cookie.del(\'login_username\');YM.cookie.del(\'mc_uuid\');return true;">退出</a></li>'





		].join('');





		d.memberTinyIcon = (d.title &&  d.title!="MEMBER_TITLE_LEVEL_00") ? d.title : d.classType;





		d.accountLink = YM.page.header.serviceAPI.accountLink;





		d.logoutLink = YM.page.header.serviceAPI.logoutLink;





		d.messageLink = YM.page.header.serviceAPI.messageLink;





		userElm.html(tmpl.substitute(d));





		if (d2.wlt) {





			userElm.addClass('co-pingan');





		}





		// 消息数显示





		if (d.messageCount && d.messageCount.all) {





			this.showMessageInfo(d.messageCount);





		}		





		// 存酒库提醒显示





		if (d.cellarTakeAlarmCount) {





			this.showCellarTakeAlarm(d.cellarTakeAlarmCount);





		}





		// QQ用户登录，头部增加一个说明条





		if (d.showMsg) {





			var cb = $('<div class="head-qqcb"></div>');





			headbarElm.before(cb);





			cb.html('<div class="wcontent">'+ d.showMsg +'<span class="cb_showmsg">'+ d.nickName +'</span></div>');





		}





	};





	YM.page.header.showMessageInfo = function(d) {





		var userElm = this.container.find('.userinfos');





		userElm.find('li.message em').html('('+d.all+')');





		userElm.find('li.message').show();





		if (d.gift>0 || d.back>0) {





			d.messageLink = this.serviceAPI.messageLink;





			userElm.find('li.message').addClass('dropdown');





			userElm.find('li.message a').addClass('txt-down');





			userElm.find('li.message').append('<ul></ul><b class="arrow-top"></b>');





			userElm.find('li.message ul').append('<li><a href="{messageLink}" target="_blank">系统消息<em>{sys}</em></a></li>'.substitute(d));





			if (d.gift>0) userElm.find('li.message ul').append('<li><a href="{messageLink}?msg_type=1" target="_blank">礼品消息<em>{gift}</em></a></dd>'.substitute(d));





			if (d.back>0) userElm.find('li.message ul').append('<li><a href="{messageLink}?msg_type=2" target="_blank">返现消息<em>{back}</em></a></dd>'.substitute(d));





			userElm.find('li.message').bindYMUI('ElementHover', { hoverClass:'dropdown-hover' });





		}





	};





	YM.page.header.showCellarTakeAlarm = function(count) {





		// 存酒库到期提醒





		if (YM.cookie.get('cellarTakeAlarmFlag')==1) return;





		YM.page.msgtip('#header ul.sitelinks li.myaccount', '<a href="http://www.yesmywine.com/personalCenter/showMyCellar.jspa?viewFlag=1" target="_blank">您的存酒库内有<strong style="color:#f00;margin:0 5px;">'+ count +'</strong>瓶酒即将到期！</a>', {position:'yellow',width:250});





		YM.load('util-msgtip', function() {





			$('.util-msgtip .msgtip-close').click(function() {





				YM.cookie.set('cellarTakeAlarmFlag', 1, 0);





			});





			$('.util-msgtip .msgtip-content a').click(function() {





				YM.cookie.set('cellarTakeAlarmFlag', 1, 0);





				return true;





			});





		});





	};





	//-----------------------------





	// 加载购物车信息 YM.page.header.cart





	YM.namespace('YM.page.header.cart');





	YM.page.header.cart.addGood = function(goodsId, amountId, goodsYearId) {





		// 此方法会在http://www.yesmywine.com/cart3/js/cart_api.js中重新定义





	};





	YM.page.header.cart.delGood = function(goodsId, cartType) {





		// 此方法会在http://www.yesmywine.com/cart3/js/cart_api.js中重新定义





	};





	YM.page.header.cart.float = function() {





		$('.head-shopcart').bindYMUI('floatTopNav');





	};





	YM.page.header.cart.show = function(d) {





		var headcartElm = $('.head-shopcart');





		if (headcartElm.size()==0) return;





		if (d.totalGoodsAmount) {





			headcartElm.find('.txt-cartcount').html(d.totalGoodsAmount).show();





			headcartElm.find('.shopcart-list').html('<ul></ul>');





			var tmpl = {





				'li': [





					'<li data-goodsId="{goodsId}">',





						'<a href="http://www.yesmywine.com/goods/{goodsId}.html" target="_blank" class="prod-info">',





							'<img src="other/.com/other/.com/other/.com/other/.com/other/.com/{goodsPicUrl}" width="60" height="98" alt="{goodsName}" />',





							'<span class="name">{goodsName}</span>',





							'<span class="nameEn">{engName}</span>',





							'<span class="price"><strong>&yen; {privilegePrice}</strong> × <em>{goodsAmount}</em></span>',





						'</a>',





						'{statusHTML}',





						'<a href="#" class="btn-remove" data-goodsId="{goodsId}" data-cartKey="{cartKey}" data-cartType="{cartType}" title="从购物车移除{goodsName}">删除</a>',





					'</li>'





				].join(''),





				'sum': [





					'<div class="shopcart-sum">',





						'<a href="http://www.yesmywine.com/cart2/showCart.jspa" class="btn-viewcart">查看购物车</a>',





						'<p>{sumHTML}<br/>总计： &yen;<strong>{totalPrice}</strong></p>',





					'</div>'





				].join('')





			};





			var li_html = '', amount=0;





			for (var i=0; i<d.goodsList.length && i<5; i++) {





				// d.goodsList[i].statusHTML = ()?'<label class="soldout">售罄</label>':'';





				d.goodsList[i].privilegePrice = d.goodsList[i].privilegePrice.toFixed(1);





				li_html += tmpl.li.substitute(d.goodsList[i]);





				amount += d.goodsList[i].goodsAmount;





			}





			headcartElm.find('.shopcart-list ul').html(li_html);





			var dsum = { totalPrice: d.totalPrice.toFixed(1) };





			if (d.totalGoodsAmount>amount) {





				dsum.sumHTML = '购物车还有<em>'+ (d.totalGoodsAmount-amount) +'</em>件商品，共<em>'+ d.totalGoodsAmount +'</em>件';





			} else {





				dsum.sumHTML = '共<em>'+ d.totalGoodsAmount +'</em>件商品';





			}





			headcartElm.find('.shopcart-list').append(tmpl.sum.substitute(dsum));





			headcartElm.find('.shopcart-list .btn-remove').click(function() {





				var goodsId = $(this).attr('data-goodsId');





				var cartKey = $(this).attr('data-cartKey');





				var cartType = $(this).attr('data-cartType');





				YM.page.header.cart.delGood(cartKey||goodsId, cartType);





				return false;





			});





		} else {





			//headcartElm.find('.txt-cartcount').html('0').hide();





			//headcartElm.find('.shopcart-list').html('<div class="empty">您的购物车内暂时没有商品，去<a href="http://www.yesmywine.com/">首页</a>挑选</div>');





		}





	};	





	YM.page.header.cart.update = function() {





		var headcartElm = $('.head-shopcart');





		if (headcartElm.size()==0) return;





		//





		if (this.isLoading) return;





		this.isLoading = true;





		YM.login.loadUserInfo(function(userData, headData) {





			YM.page.header.cart.isLoading = false;





			YM.page.header.cart.show(headData.cartInfo);





			YM.page.header.cart.slideDown();





		});





	};





	YM.page.header.cart.slideDown = function() {





		if (this.isShow) {





			if (this.timer) {





				window.clearTimeout(this.timer);





			}





		} else {





			this.isShow = true;





			$('.head-shopcart .shopcart-list').stop().removeAttr('style').slideDown();





		}





		this.timer = setTimeout(YM.page.header.cart.slideUp, 3000);





	};





	YM.page.header.cart.slideUp = function() {





		YM.page.header.cart.timer = null;





		YM.page.header.cart.isShow = false;





		var listElm = $('.head-shopcart .shopcart-list');





		listElm.slideUp(function() {





			listElm.removeAttr('style');





		});





	};





	YM.page.header.cart.slideStop = function() {





		if (YM.page.header.cart.timer) {





			window.clearTimeout(YM.page.header.cart.timer);





		}





		YM.page.header.cart.timer = false;





		YM.page.header.cart.isShow = false;





		$('.head-shopcart .shopcart-list').stop().show().removeAttr('style');





	};





	//-----------------------------





	YM.page.header.initFooter = function() {





		if ($('#footer .foot-links p a').size()==0) {





			$('#footer .foot-links').hide();





		}





		if ($.browser.isIE6) {





			$('p.sns span.ico-weixin').bindYMUI('ElementHover', { hoverClass:'ico-weixin-hover' });





		}





	};





	//-----------------------------





	// 页面内容初始化





	YM.page.header.initContent = function() {





		this.initDelayLoad();





		this.initFloatTool();





		this.initTopline();





		this.initPopCart();





		this.initGoodsInfo();





	};





	//-----------------------------





	// 内容(包括页面图片)延迟加载





	YM.page.header.initDelayLoad = function() {





		var ImageDelayLoad = function() {





			if ($('.e-imageload').size()==0) {





				$(window).unbind('scroll', ImageDelayLoad);





				$(window).unbind('resize', ImageDelayLoad);





			} else {





				$('.e-imageload').bindYMUI('DelayLoadImage', {preloadHeight:100});





			}





		};





		$(window).bind('scroll', ImageDelayLoad);





		$(window).bind('resize', ImageDelayLoad);





		ImageDelayLoad();





	};





	// 右侧浮动广告





	YM.page.header.initFloatTool = function() {





		$('#floatTool li[rel]').click(function() {





			window.scrollTo(0, $($(this).attr('rel')).offset().top);





			return false;





		});





		$('#floatTool').bindYMUI('FloatTool');





	};





	// 头部通栏处理





	YM.page.header.initTopline = function() {





		$('.e-topline').each(function() {





			var canShow = true;





			var d = new Date();





			var btime = ($(this).attr('btime') || '2000-01-01').parseDate(); 





			var etime = ($(this).attr('etime') || '2099-01-01').parseDate();





			var topic = $(this).attr('topic') || '';





			$(this).removeAttr('btime').removeAttr('etime').removeAttr('topic').removeClass('e-topline');





			if (topic != '') {





				if (typeof(m_topicId)=='undefined') {





					m_topicId = 'subject';





					if (location.pathname=='/marketing/sales/sales.html') m_topicId = 'grabbuy';





				}





				canShow = (topic.split(',').indexOf(m_topicId)>=0) ? true : false;





			}





			if (canShow && d>btime && d<etime) {





				$(this).slideDown();





				$(this).find('.countdown').bindYMUI('CountDown');





				$(this).find('img[original]').bindYMUI('LoadRealImage', {srcAttr:'original'});





			}





		});		





	};





	// 加入购物车弹窗处理





	YM.page.header.initPopCart = function() {





		var elements = $('.e-addtopopcart');





		if (elements.size()>0) {





			YM.load('popcart');





		}





		elements.click(function() {





			YM.page.AddToPopCart($(this).attr('data-goodsId'));





			return false;





		});





	};





	YM.page.AddToPopCart = function(goodsId) {





		YM.load('popcart', function() { YM.page.popcart.show(goodsId); });





	};





	// 商品信息处理





	YM.page.header.initGoodsInfo = function() {





		// 折扣率计算





		$('.promo-icon ins.zhe').each(function() {





			var itemElm = $(this).closest('li');





			var minprice = itemElm.find('.minprice strong').text(), maxprice = itemElm.find('.maxprice del').text().replace('¥','').replace('￥','');





			if (minprice>0 && maxprice>0) {





				var discount = (minprice * 10 / maxprice).toFixed(1);





				if (discount != '10.0')	{





					$(this).html('<em>'+ discount +'<\/em>折').removeClass('zhe');





				}





			}





		});





	};





	//-----------------------------





	YM.load.add('suggest', { js:'js/ym/ui/suggest.js' });





	YM.load.add('popcart', { js:'js/app/module/mod_popcart.js?vt=1', css:'css/module/mod_popcart.css' });





	//-----------------------------





	$(document).ready(function() {





		YM.page.header.init();





		YM.page.header.initContent();





	});





	//-----------------------------





})(jQuery);